package com.kgc.itrip.controller;

import com.kgc.itrip.dto.Dto;
import com.kgc.itrip.service.ItripUserLinkUserService;
import com.kgc.itrip.service.TokenService;
import com.kgc.itrip.vo.ItripAddUserLinkUserVO;
import com.kgc.itrip.vo.ItripSearchUserLinkUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@Api(value = "新增常用联系人接口")
@RequestMapping(value = "/api/userinfo")
public class UserInfoController {
    @Resource
    private TokenService tokenService;
    @Resource
    private ItripUserLinkUserService itripUserLinkUserService;


    @ApiOperation(value = "新增常用联系人接口",
            httpMethod = "POST", notes = "新增常用联系人接口",
            protocols = "http", produces = "application/json;charset=UTF-8",
            consumes = "application.json")
    @PostMapping(value = "/adduserlinkuser")
    public Dto addUserLinkUser(@RequestBody ItripAddUserLinkUserVO itripAddUserLinkUserVO,
                               HttpServletRequest request) throws Exception {
        //获取用户token
        String token = request.getHeader("token");
        //获取agent
        String agent = request.getHeader("User-Agent");
        Dto dto = itripUserLinkUserService.addItripUserLinkUser(agent,token,itripAddUserLinkUserVO);
        return dto;
    }

    @ApiOperation(value = "查询常用联系人信息",
            httpMethod = "POST", notes = "查询常用联系人信息(可根据联系人姓名进行模糊查询)",
            protocols = "http", produces = "application/json;charset=UTF-8",
            consumes = "application.json")
    @PostMapping(value = "/queryuserlinkuser")
    public Dto queryUserLinkUser(@RequestBody ItripSearchUserLinkUserVO itripSearchUserLinkUserVO,
                                 Integer pageNo,Integer pageSize,
                               HttpServletRequest request) throws Exception {
        //获取用户token
        String token = request.getHeader("token");
        //获取agent
        String agent = request.getHeader("User-Agent");
        Dto dto = itripUserLinkUserService.queryUserLinkUser(agent,token, itripSearchUserLinkUserVO,pageNo,pageSize);
        return dto;
    }
}
